home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / jockguts.arc / DIRTTT5.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-28  |  54KB  |  1,605 lines

  1. {--------------------------------------------------------------------------}
  2. {                         TechnoJock's Turbo Toolkit                       }
  3. {                                                                          }
  4. {                              Version   5.01                              }
  5. {                                                                          }
  6. {                                                                          }
  7. {              Copyright 1986, 1989 TechnoJock Software, Inc.              }
  8. {                           All Rights Reserved                            }
  9. {                          Restricted by License                           }
  10. {--------------------------------------------------------------------------}
  11.  
  12.                      {--------------------------------}
  13.                      {       Unit:   DirTTT5          }
  14.                      {--------------------------------}
  15.  
  16.  
  17. {$S-,R-,V-,D-}
  18.  
  19. unit  DirTTT5;
  20. {Change History:    04/01/89  Changed logic if no file found and DIRFULL
  21.                               is false - Line 1174
  22. }
  23.  
  24. (*
  25. {$DEFINE DIRFULL}
  26. *)
  27.  
  28. INTERFACE
  29.  
  30. Uses DOS,CRT,FastTTT5,WinTTT5,StrnTTT5,KeyTTT5,ReadTTT5;
  31.  
  32. Const
  33.    DHelpKey = #187;                     {Alter these keys if desired.       }
  34.    DHelpStr:string[2] = 'F1';           {Note: to disable these keys, set   }
  35.    DToggleKey = #32;                    {      appropriate flags in Var D.   }
  36.    DToggleStr: string[5] = 'Space';
  37.    DZoomKey = #172;
  38. {$IFDEF DIRFULL}
  39.    DZoomStr: string[5] = 'Alt-Z';
  40.    DJumpParentKey = #176;
  41.    DJumpParentStr: string[5] = 'Alt-B';
  42.    DChangeDirKey = #174;
  43.    DChangeDirStr: string[5] = 'Alt-C';
  44.    DSortOrderKey = #152;
  45.    DSortOrderStr: string[5] = 'Alt-O';
  46.    DSortSizeKey = #159;
  47.    DSortSizeStr: string[5] = 'Alt-S';
  48.    DSortNameKey = #177;
  49.    DSortNameStr: string[5] = 'Alt-N';
  50.    DSortExtKey = #146;
  51.    DSortExtStr: string[5] = 'Alt-E';
  52.    DSortTimeKey = #148;
  53.    DSortTimeStr: string[5] = 'Alt-T';
  54.    DSortDOSKey = #160;
  55.    DSortDOSStr: string[5] = 'Alt-D';
  56.    DSortDos  = 1;
  57.    DSortName = 2;
  58.    DSortExt  = 3;
  59.    DSortSize = 4;
  60.    DSortTime = 5;
  61.    Ascending = 1;
  62.    Descending = 2;
  63. {$ENDIF}
  64.  
  65. Type
  66.    DirDisplay = record
  67.                      TopX       : byte;
  68.                      TopY       : Byte;
  69.                      Rows       : byte;
  70.                      Attrib     : byte;
  71.                      BoxType    : byte;
  72.                      BoxFCol    : byte;
  73.                      BoxBCol    : byte;
  74.                      KeyFCol    : byte;
  75.                      BacCol     : byte;
  76.                      NorFCol    : byte;
  77.                      DirFCol    : byte;
  78.                      HiFCol     : byte;
  79.                      HiBCol     : byte;
  80.                      AllowEsc   : boolean;
  81.                      ShowDetails: boolean;
  82.                      Colswide   : byte;
  83.                      DisplayInfo: boolean;
  84.                      RestoreScreen : boolean;
  85.                      AllowHelp     : boolean;
  86.                      AllowToggle   : boolean;
  87.                      AllowZoom     : boolean;
  88.                      ZoomLine      : byte;
  89.                      AllowSort     : boolean;
  90.                      InitSort      : byte;
  91.                      Asc           : byte;
  92.                      AllowCD       : boolean;
  93.                      SelectDir     : boolean;
  94.                      AllowInput    : boolean;
  95.                  end;
  96.  
  97. Var
  98.    DTTT : DirDisplay;
  99.    NoMemory : boolean;
  100.  
  101. Function Display_Directory(DIRFULLFileName: StrScreen;var Retcode:integer): StrScreen;
  102. Procedure Default_Settings;
  103.  
  104. IMPLEMENTATION
  105.  
  106.   
  107. Procedure Default_Settings;
  108. begin
  109.     With  DTTT  do
  110.     begin
  111.         TopX    := 0;
  112.         TopY    := 0;
  113.         Rows    := 0;
  114.         AllowEsc := true;
  115.         Attrib := Readonly + Directory + Archive;
  116.         BoxType := 1;
  117.         ShowDetails := true;
  118.         ColsWide := 5;
  119. {$IFDEF DIRFULL}
  120.         DisplayInfo := true;
  121.         AllowHelp := true;
  122.         AllowZoom   := true;
  123.         ZoomLine := 25;
  124.         AllowSort := true;
  125.         InitSort := DSortDOS;     {sort in DOS order}
  126.         AllowInput := True;
  127. {$ELSE}
  128.         DisplayInfo := false;
  129. {$ENDIF}
  130.         AllowCD := true;
  131.         SelectDir := false;
  132.         RestoreSCreen := true;
  133.         AllowToggle := true;
  134.         Asc := 1;
  135.         If BaseOfScreen = $b000 then
  136.         begin
  137.             BoxFCol := white;
  138.             BoxBCol := black;
  139.             KeyFCol := white;
  140.             BacCol := black;
  141.             NorFCol := white;
  142.             DirFCol := lightgray;
  143.             HiFcol := black;
  144.             HiBcol := lightgray
  145.         end
  146.         else
  147.         begin
  148.             BoxFCol := lightgray;
  149.             BoxBCol := blue;
  150.             KeyFCol := yellow;
  151.             BacCol := black;
  152.             NorFCol := white;
  153.             DirFCol := yellow;
  154.             HiFcol := black;
  155.             HiBcol := cyan;
  156.         end;
  157.     end; {with}
  158. end;
  159.  
  160.  
  161.  
  162. Function Display_Directory( DIRFULLFilename: StrScreen; var Retcode : integer): StrScreen;
  163. {
  164.               X1                                    X2
  165.      Y1 >      _____________________________________
  166.               |                                     | >
  167.               |                                     | >  Infodepth
  168.               |                                     | >
  169.      Y2 >     |_____________________________________| >
  170.               |                                     |
  171.               |                                     |
  172.               |                                     |
  173.               |                                     |
  174.               |                                     |
  175.               |                                     |
  176.      Y3 >     |_____________________________________|
  177.  
  178.  
  179.           Retcodes >    0  -  filechosen
  180.                         1  -  user escaped
  181.                         2  -  not enough memory
  182.                         3  -  no files matching
  183.                         99 -  unexpected error
  184.  
  185. }
  186. Type
  187.   FRptr = ^FR;
  188.   FR = record
  189.             Name : string[8];
  190.             Ext  : string[3];
  191.             Size : longint;
  192.             Time : longint;
  193.             Attr : byte;
  194.             Fn : integer;
  195.             PrevFR: FRptr;
  196.             NextFR : FRptr;
  197.        end;
  198.  
  199. const
  200.   OKCode = 0;           {ret codes}
  201.   EscCode = 1;
  202.   MemCode = 2;
  203.   NofilesCode = 3;
  204.   UnKnownCode = 99;
  205.   InfoDepth = 4;        {no of lines in information box, i.e.Y1 to Y2}
  206.   ReadMsg = 'Reading files';
  207.   SortMsg = 'Sorting files';
  208.   NoneMsg = 'No files ... ';
  209. var
  210.   X1,X2,Y1,Y2,Y3,R,Y3_Unzoomed : byte;{box dimensions}
  211.   StartDir : StrScreen;      {default directory}
  212.   ColumnsWide : byte;
  213.   TopFn : integer;           {file number of top file in the display}
  214.   BotFn : integer;           {file number of bottom file in the display}
  215.   HiFn  : integer;           {file number of hilighted file}
  216.   Zoomed: boolean;           {is file display extended to bottom of screen}
  217.   ShowingDetails : boolean;
  218.   PathName : StrScreen;      {the path section of filename}
  219.   FileMask : StrScreen;
  220.   FirstFile : FRptr;
  221.   List_End : FRptr;
  222.   ChosenFile: strscreen;
  223.   TotalFiles: word;
  224.   TotalDirs : word;
  225.   TotalBytes: LongInt;
  226.   Ftemp : FRPtr;
  227.   HeapTop : pointer;
  228.   DirTop : pointer;
  229.   Scrn : pointer;
  230.   CursRec : array[1..4] of byte;
  231.   SortOrder : byte;               {1-DOS, 2-Name, 3-Ext, 4-Size, 5-Time}
  232.   SortAsc : boolean;
  233.  
  234.     Function Subdirectory(B : byte):boolean;
  235.     begin
  236.         Subdirectory := ((B and Directory) = Directory);
  237.     end;
  238.  
  239.     Function FileAttribs(B:byte):StrScreen;
  240.     var
  241.       S : StrScreen;
  242.     begin
  243.         S := '    ';
  244.         If ((B and ReadOnly) = Readonly) then
  245.            S[1] := 'R';
  246.         If ((B and Hidden) = Hidden) then
  247.            S[2] := 'H';
  248.         If ((B and SysFile) = SysFile) then
  249.            S[3] := 'S';
  250.         If ((B and Archive) = Archive) then
  251.            S[4] := 'A';
  252.         FileAttribs := S;
  253.      end;
  254.  
  255.      Function LongFileDesc(F:FRptr):StrScreen;
  256.      var
  257.        DT :datetime;
  258.        S  : StrScreen;
  259.      begin
  260.          If ShowingDetails then
  261.          begin
  262.              with F^ do
  263.              begin
  264.                  UnPackTime(Time,DT);
  265.                  With DT do
  266.                  begin
  267.                      If Ext = '' then
  268.                         S := Padleft(Name,12,' ')
  269.                      else
  270.                         S :=  Padleft(Name+'.'+Ext,12,' ');                 {start with name}
  271.                      If Subdirectory(Attr) then                  {add file size}
  272.                         S := S + Padright('<DIR>',8,' ')
  273.                      else
  274.                         S := S + Padright(Int_to_Str(Size),8,' ');
  275.                      S := S + '    ';
  276.                      Case Month of                               {add month}
  277.                      1 : S := S + 'Jan ';
  278.                      2 : S := S + 'Feb ';
  279.                      3 : S := S + 'Mar ';
  280.                      4 : S := S + 'Apr ';
  281.                      5 : S := S + 'May ';
  282.                      6 : S := S + 'Jun ';
  283.                      7 : S := S + 'Jul ';
  284.                      8 : S := S + 'Aug ';
  285.                      9 : S := S + 'Sep ';
  286.                      10: S := S + 'Oct ';
  287.                      11: S := S + 'Nov ';
  288.                      12: S := S + 'Dec ';
  289.                      end;
  290.                      S :=   S                                   {add the day,year}
  291.                           + Padright(Int_to_Str(Day),2,'0')
  292.                           + ','
  293.                           + Int_to_Str(Year)
  294.                           + '    ';
  295.                      If Hour > 12 then                          {add a/p time}
  296.                         S :=  S
  297.                              +Padright(Int_to_Str(Hour-12),2,' ')
  298.                              +':'
  299.                              +Padright(Int_to_Str(Min),2,'0')
  300.                              +'p'
  301.                      else
  302.                         S :=  S
  303.                               +Padright(Int_to_Str(Hour),2,' ')
  304.                               +':'
  305.                               +Padright(Int_to_Str(Min),2,'0')
  306.                               +'a';
  307.                         S := S + '  '+FileAttribs(Attr);
  308.                  end;   {with DT}
  309.              end; {with F^}
  310.          end
  311.          else    {not one column}
  312.           If F^.Ext = '' then
  313.              S := Padleft(F^.Name,12,' ')
  314.           else
  315.              S := Padleft(F^.Name+'.'+F^.Ext,12,' ');
  316.          LongFileDesc := S;
  317.      end;
  318.  
  319.     Function PathSlash(S : StrScreen):StrScreen;
  320.     begin
  321.         If S[length(S)] <> '\' then
  322.            S := S + '\';
  323.         PathSlash := S;
  324.     end;  {Sub Func PathSlash}
  325.  
  326.     Function PathNoSlash(S : StrScreen):StrScreen;
  327.     begin
  328.         If S[length(S)] = '\' then
  329.            Delete(S,length(S),1);
  330.         PathNoSlash := S;
  331.     end;  {Sub Func PathSlash}
  332.  
  333.     Function PathParent(S : StrScreen):StrScreen;
  334.     var P1 : byte;
  335.     begin
  336.         S := PathNoSlash(S);
  337.         P1 := LastPos('\',S);
  338.         PathParent := copy(S,1,P1);
  339.     end;
  340.  
  341.     Function PathChild(S : StrScreen):StrScreen;
  342.     begin
  343.         PathChild := PathSlash(PathName + S);
  344.     end;
  345.  
  346.     Procedure Extract_Path_Mask;
  347.     var P1,P2 : byte;
  348.     begin
  349.         P1 := LastPos('\',DIRFULLFileName);
  350.         P2 := Pos(':',DIRFULLFilename);
  351.         If (P1 = 0) and (P2 = 0) then
  352.         begin
  353.             FileMask := DIRFULLFileName;
  354.             PathName := PathSlash(StartDir);
  355.             exit;
  356.         end;
  357.         If P1 = length(DIRFULLFileName) then
  358.         begin
  359.             FileMask := '*.*';
  360.             PathName := DIRFULLFileName;
  361.             exit;
  362.         end;
  363.         If (P1 = 0) and (P2 = 2) then   { x:filename.ext}
  364.         begin
  365.            Filemask := copy(DIRFULLFileName,3,length(DIRFULLFileName));
  366.            {$I-}
  367.            GetDir(ord(upcase(DIRFULLFileName[1]))-64,PathName);
  368.            {$I-}
  369.            If IOResult <> 0 then
  370.               PathName := PathSlash(StartDir)
  371.            else
  372.               PathName := PathSlash(PathName);
  373.            exit;
  374.         end;
  375.         Filemask := copy(DIRFULLFileName,succ(P1),12);
  376.         PathName := copy(DIRFULLFileName,1,P1);
  377.     end;  {Extract_Path_Mask}
  378.  
  379.     Procedure LoadFiles(Mask:StrScreen;Attrib:byte);
  380.     var
  381.       Finfo : SearchRec;
  382.       Recsize : word;
  383.  
  384.       Procedure PushOnHeap(var F:FrPtr);
  385.       var P : byte;
  386.       begin
  387.           with F^ do
  388.           begin
  389.               Attr := Finfo.Attr;
  390.               Time := Finfo.Time;
  391.               Size := Finfo.Size;
  392.               If FInfo.Name = '..' then
  393.               begin
  394.                   Name := '..';
  395.                   Ext := '';
  396.               end
  397.               else
  398.               begin
  399.                   P := pos('.',Finfo.Name);
  400.                   If P = 0 then
  401.                   begin
  402.                       Name := Finfo.Name;
  403.                       Ext := '';
  404.                  end
  405.                  else
  406.                  begin
  407.                      Name := copy(FInfo.Name,1, pred(P));
  408.                      Ext := copy(Finfo.Name,succ(P),3);
  409.                  end;
  410.               end;
  411.               Fn := succ(TotalFiles);
  412.               NextFR := nil;
  413.               PrevFr := nil;
  414.               TotalBytes := TotalBytes + Size;
  415.           end;
  416.           Inc(TotalFiles);
  417.           If Finfo.Attr = Directory then
  418.              Inc(TotalDirs);
  419.       end;   {sub sub proc TransferFileToHeap}
  420.  
  421.       Procedure AllocHeap;
  422.       begin
  423.           If ( (Attrib = Directory) and (FInfo.Attr <> Directory) ) then
  424.              exit;   {if only looking for directory entries}
  425.           If (Finfo.Name <> '.') and (DosError = 0) then
  426.           begin
  427.               If (TotalFiles = 0) then
  428.               begin
  429.                   PushOnHeap(FirstFile);
  430.                   FirstFile^.PrevFR := nil;
  431.                   Ftemp :=  FirstFile;
  432.                   List_End := FirstFile;
  433.               end
  434.               else
  435.               begin
  436.                   GetMem(Ftemp^.NextFR,Recsize);
  437.                   PushOnHeap(FTemp^.NextFr);
  438.                   FTemp := Ftemp^.NextFR;
  439.                   FTemp^.PrevFR := List_End;
  440.                   List_End := Ftemp;
  441.               end; {If TotalFiles = 0}
  442.          end; { If name <> '.'}
  443.       end;
  444.  
  445.     begin
  446.         RecSize := Sizeof(FirstFile^);
  447.         If MaxAvail < 2*Recsize then
  448.         begin
  449.             NoMemory := true;
  450.             exit;
  451.         end;
  452.         Fastwrite(X1+2,Y2+1,attr(DTTT.NorFcol+blink,DTTT.BacCol),ReadMsg);
  453.         FindFirst(PathName+Mask,Attrib,Finfo);
  454.         If DosError <> 0 then
  455.            exit;
  456.         If TotalFiles = 0 then
  457.         begin
  458.            GetMem(FirstFile,RecSize);
  459.            GetMem(List_End,RecSize);
  460.         end;
  461.         AllocHeap;
  462.         While (DosError = 0) and (NoMemory = false) do
  463.         begin
  464.             If MaxAvail < RecSize then
  465.                NoMemory := true
  466.             else
  467.             begin
  468.                 FindNext(Finfo);
  469.                 AllocHeap;
  470.             end; {If MaxAvail}
  471.         end; {while}
  472.     end; {Sub Proc Loadfiles}
  473.  
  474.     Procedure Calculate_Box_Dimensions;
  475.     var
  476.       Boxwidth : byte;
  477.     begin
  478.         If ShowingDetails then
  479.            Boxwidth := 54
  480.         else
  481.            Boxwidth := succ(DTTT.Colswide*14);
  482.         with DTTT do
  483.         begin
  484.             If (TopX < 1) or (TopX > 80) then
  485.                X1 :=  (80 - Boxwidth) div 2
  486.             else
  487.             begin
  488.                If TopX <= (80 - Boxwidth) then
  489.                   X1 := TopX
  490.                else                               {move box left until it fits}
  491.                   X1 := 80 - Boxwidth;
  492.             end;
  493.             X2 := X1 + Boxwidth;
  494.             If Rows in [1..23] then
  495.                R := Rows
  496.             else
  497.                R := 8;
  498.             If (TopY < 1) or (TopY > DisplayLines - 2) then
  499.                Y1 := 5
  500.             else
  501.                Y1 := TopY;
  502.             If not DisplayInfo then
  503.                Y2 := Y1
  504.             else
  505.             begin
  506.                 If Y1 + InfoDepth < DisplayLines - 2 then
  507.                    Y2 := Y1 + InfoDepth
  508.                 else                               {no room for info}
  509.                    Y2 := Y1;
  510.             end;
  511.             Y3 := Y2 + succ(R);
  512.             If Y3 > DisplayLines then
  513.             begin
  514.                Y3 := DisplayLines;
  515.                If Y2 <> Y1 then
  516.                begin
  517.                    Y2 := Y3 - succ(R);
  518.                    Y1 := Y2 - InfoDepth;
  519.                end
  520.                else
  521.                begin
  522.                    Y2 := Y3 - succ(R);
  523.                    Y1 := Y2;
  524.                end;
  525.             end;
  526.         end;
  527.     end;  {sub proc Calculate_Box_Dimensions}
  528.  
  529.     Procedure Display_Box;
  530.     var
  531.       LChar,Rchar : char;
  532.       Col,
  533.       I : integer;
  534.     begin
  535.         with DTTT do
  536.         begin
  537.             If Y2 = Y1 then
  538.                ClearText(X1,Y1,X2,Y3,NorFCol,Baccol)
  539.             else
  540.             begin
  541.                 ClearText(X1,Y1,X2,pred(Y2),BoxFCol,BoxBcol);
  542.                 ClearText(X1,Y2,X2,Y3,NorFCol,Baccol);
  543.             end;
  544.             Col := attr(BoxFcol,BoxBCol);
  545.             If (BoxType in [5..9]) then
  546.             begin
  547.                 Box(X1,Y1,X2,Y3,BoxFcol,BoxBcol,Boxtype-5);
  548.                 If (X2 < 80) and (Y3 < DisplayLines) then
  549.                 begin
  550.                     For I := succ(Y1) to succ(Y3) do
  551.                         Fastwrite(succ(X2),I,ShadColor,chr(219));
  552.                     Fastwrite(succ(X1),succ(Y3),ShadColor,replicate(X2-X1,chr(219)));
  553.                 end;
  554.             end
  555.             else
  556.                Box(X1,Y1,X2,Y3,BoxFcol,BoxBcol,Boxtype);
  557.             If Y2 > Y1 then
  558.             begin
  559.                 Horizline(succ(X1),pred(X2),Y2,BoxFCol,BoxBcol,Boxtype);
  560.                 Case Boxtype of
  561.                 1,6 : begin
  562.                           LChar := chr(195);
  563.                           RChar := chr(180);
  564.                       end;
  565.                 2,7 : begin
  566.                           LChar := chr(204);
  567.                           RChar := chr(185);
  568.                       end;
  569.                 3,8 : begin
  570.                           LChar := chr(199);
  571.                           RChar := chr(182);
  572.                       end;
  573.                 4,9 : begin
  574.                           LChar := chr(181);
  575.                           RChar := chr(198);
  576.                       end;
  577.                 else      Lchar := ' ';
  578.                           Rchar := ' ';
  579.                 end;  {case}
  580.                 Fastwrite(X1,Y2,Col,Lchar);
  581.                 Fastwrite(X2,Y2,Col,Rchar);
  582.             end;
  583.         end;
  584.     end;  {sub proc display box}
  585.  
  586.     Procedure DisplayPath;
  587.     var
  588.        L : byte;
  589.        Y : byte;
  590.        P : StrScreen;
  591.     begin
  592.         P := Pathname+Filemask;
  593.         L := length(P);
  594.         If Y2 = Y1 then
  595.         begin
  596.            Y := Y1;
  597.            If L > (X2-X1-2) then
  598.               P := chr(17)+copy(P,L-(X2-X1)+4,L);
  599.         end
  600.         else
  601.         begin
  602.            Y := Y1 + 2;
  603.            If L > (X2-X1-2) then
  604.               P := chr(17)+copy(P,L-(X2-X1-1)+4,L);
  605.         end;
  606.         Fastwrite(X1+2,Y,attr(DTTT.BoxFcol,DTTT.BoxBCol),P);
  607.     end;  {sub Proc DisplayPath}
  608.  
  609.  
  610.     Procedure FillInfo;
  611.     var
  612.       TB,Di : StrScreen;
  613.       C,H,L  : byte;
  614.     begin
  615.         with DTTT do
  616.         begin
  617.             C := attr(BoxFCol,BoxBCol);
  618.             H := attr(KeyFcol,BoxBCol);
  619.             If (Y2 = Y1) then
  620.             begin
  621.                 DisplayPath;
  622.                 exit;
  623.             end;
  624. {$IFDEF DIRFULL}
  625.             If  (ColumnsWide < 3 ) and (ShowingDetails = false) then
  626.             begin
  627.                 DisplayPath;
  628.                 Fastwrite(X1+2,Y1+1,H,chr(17)+char(217));
  629.                 Fastwrite(X1+5,Y1+1,C,'Select');
  630.                 Fastwrite(X1+2,Y1+3,C,'Files: ');
  631.                 Fastwrite(X1+9,Y1+3,C,Int_To_Str(TotalFiles-TotalDirs));
  632.                 exit;
  633.             end;
  634.             ClearText(succ(X1),Succ(Y1),pred(X2),Pred(Y2),BoxFcol,BoxBCol);
  635.             Fastwrite(X1 + 2,Y1 + 3,C,'Matching files: ');
  636.             Fastwrite(X1 + 18,Y1 + 3,C,Int_To_Str(TotalFiles-TotalDirs));
  637.             TB := 'Total bytes: '+Int_To_Str(TotalBytes);
  638.             Fastwrite(X2 -length(TB) - 1,Y1 + 3,C,TB);
  639.             If AllowHelp then
  640.             begin
  641.                 Fastwrite(X1+2,Y1+1,H,DHelpStr);    {Prompt at left}
  642.                 Fastwrite(X1+3+length(DHelpStr),Y1+1,C,'Help');
  643.             end;
  644.             L := pred(X1)
  645.                + ((X2-X1) div 2)
  646.                - (length(DToggleStr)+ 7) div 2;     {next prompt in center}
  647.             Fastwrite(L,Y1+1,H,chr(17)+char(217));
  648.             L := L + 3;
  649.             Fastwrite(L,Y1+1,C,'Select');
  650.             If AllowToggle then
  651.             begin
  652.                 L := X2 - length(DToggleStr) - 8;   {right justified}
  653.                 Fastwrite(L,Y1+1,H,DToggleStr);
  654.                 L := L + 1 + length(DToggleStr);
  655.                 Fastwrite(L,Y1+1,C,'Toggle');
  656.             end;
  657.         end;
  658.         DisplayPath;
  659. {$ELSE}
  660.        end;
  661. {$ENDIF}
  662.     end;  {sub proc Fillinfo}
  663.  
  664.     Function FilePointer(Fn:word): FRptr;
  665.     {MODIFY to go from current pointer - for speed}
  666.     var
  667.       P : FRptr;
  668.       I : integer;
  669.     begin
  670.         If  SortAsc then
  671.         begin
  672.             P := FirstFile;
  673.             If Fn > 1 then
  674.                For I := 2 to Fn do
  675.                    P := P^.NextFr;
  676.         end
  677.         else {Descending}
  678.         begin
  679.             P := List_End;
  680.             If Fn > 1 then
  681.                For I := 2 to Fn do
  682.                    P := P^.PrevFr;
  683.         end;
  684.         FilePointer := P;
  685.     end;  {sub proc filepointer}
  686.  
  687.     Function Y_Coord(Fn : word):byte;
  688.     begin
  689.          Y_Coord := Succ(Y2) + ((Fn-TopFn) DIV ColumnsWide);
  690.     end;
  691.  
  692.     Function X_Coord(Fn : word):byte;
  693.     begin
  694.            X_Coord := succ(X1) + 14*((Fn-TopFn) MOD Columnswide);
  695.     end;
  696.  
  697.     Function TopLine:Boolean;
  698.     begin
  699.           TopLine := (HiFn <= ColumnsWide);
  700.     end;
  701.  
  702.     Function BottomLine:Boolean;
  703.     begin
  704.           BottomLine := (HiFn + ColumnsWide > TotalFiles);
  705.     end;
  706.  
  707.     Function FirstColumn:boolean;
  708.     begin
  709.            If Columnswide = 1 then
  710.               FirstColumn := true
  711.            else
  712.               FirstColumn := (HiFn MOD ColumnsWide = 1);
  713.     end;
  714.  
  715.     Function LastColumn:boolean;
  716.     begin
  717.            LastColumn := (HiFn MOD ColumnsWide = 0);
  718.     end;
  719.  
  720.     Procedure RecalcTopFn;
  721.     begin
  722.         If ColumnsWide = 1 then
  723.            TopFn := succ(BotFn -R)
  724.         else
  725.             TopFn :=  Succ(   BotFn
  726.                             - pred(R)*ColumnsWide
  727.                             - BotFn MOD ColumnsWide
  728.                           );
  729.     end;
  730.  
  731.     Procedure RecalcBotFn;
  732.     begin
  733.         BotFn := pred( TopFn + ColumnsWide*R);
  734.         If BotFn > TotalFiles then
  735.            BotFn := TotalFiles;
  736.     end;
  737.  
  738.     Procedure LolightFile(Fn:word);
  739.     var
  740.       C : byte;
  741.       F : FRptr;
  742.     begin
  743.         If (Fn < TopFn) or (Fn > BotFn ) then
  744.            exit;    {file not in display area}
  745.         F := Filepointer(Fn);
  746.         If Subdirectory(F^.Attr) then
  747.            C := attr(DTTT.DirFcol,DTTT.BacCol)
  748.         else
  749.            C := attr(DTTT.NorFCol,DTTT.BacCol);
  750.         Fastwrite(X_Coord(Fn),
  751.                   Y_Coord(Fn),
  752.                   C,
  753.                   ' '+LongFileDesc(F)+' ');
  754.     end;
  755.  
  756.     Procedure HilightFile(Fn:word);
  757.     var
  758.       F : FRptr;
  759.     begin
  760.         If (Fn < TopFn) or (Fn > BotFn) then
  761.            exit;    {file not in display area}
  762.         F := Filepointer(Fn);
  763.         Fastwrite(X_Coord(Fn),
  764.                   Y_Coord(Fn),
  765.                   attr(DTTT.HiFcol,DTTT.HiBCol),
  766.                   +' '+LongFileDesc(F)+' ')
  767.     end;
  768.  
  769.     Function File_name(Fn : word):StrScreen;
  770.     var
  771.        F : FRPtr;
  772.        Fname : strscreen;
  773.     begin
  774.         F := FilePointer(Fn);
  775.         Fname := F^.Name;
  776.         If F^.Ext <> '' then
  777.            Fname := Fname+'.'+F^.Ext;
  778.         File_Name := Fname;
  779.     end;   {Sub Funct File_name}
  780.  
  781.     Procedure DisplayFiles;
  782.     var
  783.       I : integer;
  784.     begin
  785.         If (Columnswide > 1) and (BotFn = TotalFiles) then    {clear line}
  786.            ClearText(succ(X1),pred(Y3),Pred(X2),pred(Y3),DTTT.NorFcol,DTTT.BacCol);
  787.         For I := TopFn to BotFn do
  788.             If (I <> HiFn) and (I <= TotalFiles) then
  789.                LolightFile(I);
  790.         HiLightFile(HiFn);
  791.     end; {sub proc DisplayFiles}
  792.  
  793.     Procedure Scroll_Down;
  794.     begin
  795.         TopFn := TopFn + Columnswide;
  796.         RecalcBotFn;
  797.         DisplayFiles;
  798.     end; {scroll_down}
  799.  
  800.     Procedure Scroll_Up;
  801.     begin
  802.         TopFn := TopFn - Columnswide;
  803.         RecalcBotFn;
  804.         DisplayFiles;
  805.     end; {scroll_up}
  806.  
  807.     Procedure Scroll_Top;
  808.     begin
  809.         TopFn := 1;
  810.         RecalcBotFn;
  811.         HiFn := 1;
  812.         DisplayFiles;
  813.     end; {scroll_Home}
  814.  
  815.     Procedure Scroll_Bottom;
  816.     begin
  817.         TopFn := succ(TotalFiles - R);
  818.         BotFn := TotalFiles;
  819.         HiFn := TotalFiles;
  820.         DisplayFiles;
  821.     end; {scroll_Home}
  822.  
  823.  
  824. {\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\    SORTING   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}
  825. {$IFDEF DIRFULL}
  826.  
  827. Function Larger(Ptr1,Ptr2: FRptr) : boolean;
  828. var
  829.    N1,N2 : string[8];
  830.    E1,E2 : string[8];
  831. begin
  832.     Case SortOrder of
  833.     DSortDos   : Larger := (Ptr1^.Fn > Ptr2^.Fn);
  834.     DSortNAME  : If Ptr1^.Name = Ptr2^.Name then
  835.                     Larger := Ptr1^.Ext > Ptr2^.Ext
  836.                  else
  837.                     Larger := Ptr1^.Name > Ptr2^.Name;
  838.     DSortEXT   : If Ptr1^.Ext = Ptr2^.Ext then
  839.                     Larger := Ptr1^.Name > Ptr2^.Name
  840.                  else
  841.                     Larger := Ptr1^.Ext > Ptr2^.Ext;
  842.     DSortSIZE  : Larger := (Ptr1^.Size > Ptr2^.Size);
  843.     DSortTIME  : Larger := (Ptr1^.Time > Ptr2^.Time);
  844.     else Larger := false;
  845.     end; {Case}
  846. end; {suc proc larger}
  847.  
  848. Procedure SwapIt(var Ptr1,Ptr2: FRPtr);
  849. var
  850.    Temp : FR;
  851.    Size : integer;
  852. begin
  853.     Temp := Ptr2^;
  854.     Size := sizeof(Temp) - 8;
  855.     Move(Ptr1^,Ptr2^,Size);
  856.     Move(Temp,Ptr1^,Size);
  857. end;  {sub proc Swap}
  858.  
  859. Procedure ShellSort;
  860. var
  861.    I,J,Delta : longint;
  862.    Swapped : boolean;
  863.    Ptr1,Ptr2 : FRPtr;
  864.  
  865. begin
  866.     Delta := TotalFiles div 2;
  867.     repeat
  868.          Repeat
  869.               Swapped := false;
  870.               Ptr1 := FirstFile;
  871.               Ptr2 := Ptr1;
  872.               For I := 1 to Delta do
  873.                   Ptr2 := Ptr2^.NextFr;
  874.               For I := 1 to TotalFiles - Delta do
  875.               begin
  876.                   If I > 1 then
  877.                   begin
  878.                       Ptr1 := Ptr1^.NextFr;
  879.                       Ptr2 := Ptr2^.NextFr;
  880.                   end;
  881.                   If Larger(Ptr1,Ptr2) then
  882.                   begin
  883.                       SwapIt(Ptr1,Ptr2);
  884.                       Swapped := true;
  885.                   end;
  886.               end;
  887.          Until (not Swapped);
  888.          Delta := delta div 2;
  889.     Until Delta = 0;
  890. end;
  891.  
  892.                 Procedure ReSort;
  893.                 begin
  894.                     ClearText(succ(X1),Succ(Y2),pred(X2),pred(Y3),DTTT.NorFcol,DTTT.BacCol);
  895.                     Fastwrite(X1 + 2,succ(Y2),attr(DTTT.NorFcol+blink,DTTT.BacCol),SortMsg);
  896.                     ShellSort;
  897.                     TopFn := 1;
  898.                     HiFn := 1;
  899.                     RecalcBotFn;
  900.                     DisplayFiles;
  901.                 end;
  902. {$ENDIF}
  903.  
  904.     Procedure DisplayNewDirectory;
  905.     var A : byte;
  906.     begin
  907.         A := DTTT.attrib and (AnyFile - VolumeID);
  908.         Display_Box;
  909.         TotalFiles := 0;
  910.         TotalBytes := 0;
  911.         TotalDirs  := 0;
  912.         Mark(DirTop);
  913.         If DTTT.AllowCd or DTTT.SelectDir then
  914.         begin
  915.             If Subdirectory(A) then
  916.             begin
  917.                  LoadFiles('*.*',Directory);                {load directory details first}
  918.                  Loadfiles(Filemask,A and (anyfile - Directory));  {then load other files with mask}
  919.             end
  920.             else
  921.                  LoadFiles(Filemask,A and (Anyfile - Directory));
  922.         end
  923.         else                  {automatically removed directory type files}
  924.              LoadFiles(Filemask,A and (anyfile - Directory));
  925.         FillInfo;
  926. {$IFDEF DIRFULL}
  927.         If SortOrder <> DSortDOS then
  928.            ShellSort;
  929. {$ENDIF}
  930.         If TotalFiles = 0 then
  931.            Fastwrite(X1+2,Y2+1,attr(DTTT.NorFcol,DTTT.BacCol),NoneMsg)
  932.         else
  933.            Scroll_Top;
  934.     end;  {sub proc DisplayNewDirectory}
  935.  
  936. {$IFDEF DIRFULL}
  937.     Procedure ShowHelpScreen;
  938.     const
  939.         width = 55;
  940.         depth = 14;
  941.     var
  942.       Str : StrScreen;
  943.       S  : word;
  944.       Sc : pointer;
  945.       X,Y : byte;
  946.       ChH : char;
  947.     begin
  948.         If X1 + width > 80 then
  949.            X := pred((80 - width) div 2)
  950.         else
  951.            X := X1;
  952.         If Y1 + Depth > DisplayLines then
  953.            Y := pred((DisplayLines -Depth) div 2)
  954.         else
  955.            Y := Y1;
  956.         S := 160*DisplayLines;
  957.         If MaxAvail < S then
  958.            exit;
  959.         GetMem(Sc,S);
  960.         MoveFromScreen(Mem[BaseOfScreen:0],Sc^,S Div 2);
  961.         FBox(X,Y,pred(X+ width),pred(Y+Depth),DTTT.BoxFCol,DTTT.BoxBCol,1);
  962.         Case SortOrder of
  963.         DSortDos  : Str := ' DOS';
  964.         DSortName : Str := ' NAME';
  965.         DSortExt  : Str := ' EXT';
  966.         DSortSize : Str := ' SIZE';
  967.         DSortTime : Str := ' TIME';
  968.         end; {case}
  969.         If SortAsc then
  970.            Str := Str +' in ASCENDING order'
  971.         else
  972.            Str := Str +' in DESCENDING order';
  973.         If Zoomed then
  974.            Str := Str +' (Zoomed) '
  975.         else
  976.            Str := Str+' (not zoomed) ';
  977.         Str := ' Current: '+Str;
  978.         WriteBetween(X,X + Width,pred(Y)+depth,DTTT.KeyFCol,DTTT.BoxBCol,Str);
  979.         If DTTT.AllowSort then
  980.         begin
  981.             Fastwrite(X+4,Y+2,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortDOSStr);
  982.             Fastwrite(X+7+length(DSortDOSStr),Y+2,
  983.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  984.                       'sort in native DOS order');
  985.             Fastwrite(X+4,Y+3,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortNameStr);
  986.             Fastwrite(X+7+length(DSortNameStr),Y+3,
  987.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  988.                       'sort alphabetically by file Name');
  989.             Fastwrite(X+4,Y+4,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortExtStr);
  990.             Fastwrite(X+7+length(DSortExtStr),Y+4,
  991.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  992.                       'sort alphabetically by file Extension');
  993.             Fastwrite(X+4,Y+5,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortSizeStr);
  994.             Fastwrite(X+7+length(DSortSizeStr),Y+5,
  995.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  996.                       'sort by file Size');
  997.             Fastwrite(X+4,Y+6,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortTimeStr);
  998.             Fastwrite(X+7+length(DSortTimeStr),Y+6,
  999.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1000.                       'sort by date/Time of file');
  1001.             Fastwrite(X+4,Y+7,attr(DTTT.KeyFCol,DTTT.BoxBCol),DSortOrderStr);
  1002.             Fastwrite(X+7+length(DSortOrderStr),Y+7,
  1003.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1004.                       'sort in ascending or descending Order');
  1005.         end
  1006.         else
  1007.            WriteBetween(X,X+Width,Y+3,DTTT.BoxFCol,DTTT.BoxBCol,'SORTING DISABLED');
  1008.         If DTTT.AllowZoom then
  1009.         begin
  1010.             Fastwrite(X+4,Y+9,attr(DTTT.KeyFCol,DTTT.BoxBCol),DZoomStr);
  1011.             Fastwrite(X+7+length(DZoomStr),Y+9,
  1012.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1013.                       'toggle long/short box size');
  1014.         end;
  1015.         If DTTT.AllowCD then
  1016.         begin
  1017.             Fastwrite(X+4,Y+11,attr(DTTT.KeyFCol,DTTT.BoxBCol),DChangeDirStr);
  1018.             Fastwrite(X+7+length(DChangeDirStr),Y+11,
  1019.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1020.                       'change to new drive/directory');
  1021.             Fastwrite(X+4,Y+12,attr(DTTT.KeyFCol,DTTT.BoxBCol),DJumpParentSTr);
  1022.             Fastwrite(X+7+length(DJumpParentStr),Y+12,
  1023.                       attr(DTTT.BoxFCol,DTTT.BoxBCol),
  1024.                       'backup to parent directory');
  1025.         end;
  1026.         WriteBetween(X, X + Width, Y,
  1027.                      DTTT.BoxFCol + Blink, DTTT.BoxBCol,
  1028.                      ' press any key ... ');
  1029.  
  1030.         ChH := upcase(GetKey);
  1031.         MoveToScreen(Sc^,Mem[BaseOfScreen:0], S Div 2);
  1032.         FreeMem(Sc,S);
  1033.     end;
  1034.  
  1035.     Procedure PromptForDirectory;
  1036.     const
  1037.        width = 55;
  1038.     var
  1039.        S : word;
  1040.        Sc : pointer;
  1041.        X : byte;
  1042.        OldP,OldM,Strng : String;
  1043.     begin
  1044.         S := 160*DisplayLines;
  1045.         If MaxAvail < S then
  1046.            exit;
  1047.         OldP := Pathname;
  1048.         OldM := FileMask;
  1049.         GetMem(Sc,S);
  1050.         MoveFromScreen(Mem[BaseOfScreen:0],Sc^,S Div 2);    {SaveThescreen}
  1051.         If X1 + width > 80 then
  1052.            X := pred((80 - width) div 2)
  1053.         else
  1054.            X := X1;
  1055.         FBox(X,Y1,pred(X + width),Y1 + 2,DTTT.BoxFCol,DTTT.BoxBCol,2);
  1056.         WriteBetween(X,X+Width,Y1,DTTT.KeyFCol,DTTT.BoxBCol,'  Directory of Files  ');
  1057.         Strng := PathName+FileMask;
  1058.         Read_String_Upper(X+1,Y1+1,width - 2,'',0,Strng);
  1059.         MoveToScreen(Sc^,Mem[BaseOfScreen:0], S Div 2);
  1060.         FreeMem(Sc,S);
  1061.         If (R_Char <> #027) then
  1062.         begin
  1063.             DIRFULLFileName := Strng;
  1064.             Extract_Path_Mask;
  1065.             Release(DirTop);
  1066.             DisplayNewDirectory;
  1067.             If TotalFiles = 0 then   {re-read original directory}
  1068.             begin
  1069.                sound(800);delay(200);nosound;
  1070.                PathName := OldP;
  1071.                FileMask := OldM;
  1072.                Release(DirTop);
  1073.                DisplayNewDirectory;
  1074.             end;
  1075.         end;
  1076.     end;
  1077.  
  1078.     Function PromptForFilename(C:char):string;
  1079.     const
  1080.        width = 55;
  1081.     var
  1082.        S : word;
  1083.        Sc : pointer;
  1084.        X : byte;
  1085.        Strng : String;
  1086.        Msg : Strscreen;
  1087.     begin
  1088.         S := 160*DisplayLines;
  1089.         If MaxAvail < S then
  1090.            exit;
  1091.         GetMem(Sc,S);
  1092.         MoveFromScreen(Mem[BaseOfScreen:0],Sc^,S Div 2);    {SaveThescreen}
  1093.         If X1 + width > 80 then
  1094.            X := pred((80 - width) div 2)
  1095.         else
  1096.            X := X1;
  1097.         FBox(X,Y1,pred(X + width),Y1 + 2,DTTT.BoxFCol,DTTT.BoxBCol,2);
  1098.         If C = #0 then
  1099.         begin
  1100.            Msg := '  No files  - enter filename  ';
  1101.            Strng := '';
  1102.         end
  1103.         else
  1104.         begin
  1105.            Msg := '  Enter filename (or Esc)  ';
  1106.            Strng := C;
  1107.         end;
  1108.         WriteBetween(X,X+Width,Y1,DTTT.KeyFCol,DTTT.BoxBCol,Msg);
  1109.         Read_String_Upper(X+1,Y1+1,width-2,'',0,Strng);
  1110.         MoveToScreen(Sc^,Mem[BaseOfScreen:0], S Div 2);
  1111.         FreeMem(Sc,S);
  1112.         If (R_Char <> #027) then
  1113.             PromptForFilename := Strng
  1114.         else
  1115.             PromptForFilename := '';
  1116.     end;
  1117.  
  1118. {$ENDIF}
  1119.  
  1120. {\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}
  1121. {$IFDEF DIRFULL}
  1122.      Function No_Files_Found: integer;
  1123.      {returns 99 if user escaped
  1124.            or 0  if user enter a file
  1125.      }
  1126.      begin
  1127.  
  1128.          ChosenFile := PromptForFilename(#0);
  1129.          If ChosenFile = '' then
  1130.          begin
  1131.              No_Files_Found := 99;
  1132.              exit;
  1133.          end;
  1134.          If (pos('*',ChosenFile) > 0)
  1135.          or (pos('?',ChosenFile) > 0)
  1136.          or (ChosenFile[Length(ChosenFile)] = '\') then
  1137.          begin
  1138.              DIRFULLFileName := ChosenFile;
  1139.              Extract_Path_Mask;
  1140.              Release(DirTop);
  1141.              DisplayNewDirectory;
  1142.          end
  1143.          else
  1144.          begin
  1145.              If  (pos('\',ChosenFile) = 0)
  1146.              and (pos(':',ChosenFile) = 0) then
  1147.              begin
  1148.                  ChosenFile := PathName + ChosenFile;
  1149.                  No_Files_Found := 0;
  1150.                  exit;
  1151.              end;
  1152.          end;
  1153.          No_Files_Found := 1;
  1154.      end; {of func No_Files_Found}
  1155. {$ENDIF}
  1156.  
  1157.     Procedure Process_Keys;
  1158.     var
  1159.       ChD : char;
  1160.       Finished : Boolean;
  1161.     begin
  1162.         Finished := false;
  1163.         If TotalFiles = 0 then
  1164.         begin
  1165. {$IFDEF DIRFULL}
  1166.             Repeat
  1167.                  Case No_Files_Found of
  1168.                  0 : exit;  {user selected a file}
  1169.                  99: begin  {user escaped}
  1170.                          Retcode := NoFilesCode;
  1171.                          Exit;
  1172.                      end;
  1173.                  end; {case}
  1174.             until TotalFiles <> 0;
  1175. {$ELSE}
  1176.            Retcode := NoFilesCode;
  1177.            WriteAt(succ(X1),succ(Y2),DTTT.DirFCol,DTTT.BoxBCol,       {5.01}
  1178.            'No files found.... press any key');
  1179.            ChD := GetKey;
  1180.            Exit;
  1181. {$ENDIF}
  1182.         end;
  1183.         Repeat
  1184.              ChD := upcase(GetKey);
  1185.              Case ChD of
  1186.              #129,                  {mouse down, down arrow}
  1187.              #208 :  If not BottomLine then
  1188.                      begin
  1189.                          LoLightFile(HiFn);
  1190.                          Hifn := HiFn + Columnswide;
  1191.                          If HiFn <= BotFn then
  1192.                             HiLightFile(HiFn)
  1193.                          else
  1194.                             Scroll_Down;
  1195.                      end;
  1196.              #128,                      {mouse up, up arrow}
  1197.              #200 : If not TopLine then
  1198.                     begin
  1199.                         LoLightFile(HiFn);
  1200.                         Hifn := HiFn - Columnswide;
  1201.                         If HiFn >= TopFn then
  1202.                            HiLightFile(HiFn)
  1203.                         else
  1204.                            Scroll_Up;
  1205.                     end;
  1206.              #205 : If HiFn < TotalFiles then  {right arrow}
  1207.                     begin
  1208.                         LolightFile(HiFn);
  1209.                         Inc(HiFn);
  1210.                         If HiFn > BotFn then
  1211.                            Scroll_Down
  1212.                         else
  1213.                            HiLightFile(HiFn);
  1214.                     end;
  1215.              #131 : If  (LastColumn = false) and (HiFn < BotFn) then  {mouse right}
  1216.                     begin
  1217.                         LolightFile(HiFn);
  1218.                         Inc(HiFn);
  1219.                         HiLightFile(HiFn);
  1220.                     end;
  1221.              #130 : If (FirstColumn = false) then   {mouse left}
  1222.                     begin
  1223.                        LolightFile(HiFn);
  1224.                        Dec(HiFn);
  1225.                        HiLightFile(HiFn);
  1226.                     end;
  1227.              #203 : If HiFn > 1 then {Left arrow}
  1228.                     begin
  1229.                         LolightFile(HiFn);
  1230.                         Dec(HiFn);
  1231.                         If HiFn < TopFn then
  1232.                            Scroll_Up
  1233.                         else
  1234.                            HiLightFile(HiFn);
  1235.                     end;
  1236.              #199 : If Columnswide = 1 then
  1237.                     begin
  1238.                         If TopFn = 1 then
  1239.                         begin
  1240.                             LoLightFile(HiFn);
  1241.                             HiFn := 1;
  1242.                              HiLightFile(HiFn);
  1243.                         end
  1244.                         else
  1245.                            Scroll_Top;
  1246.                     end
  1247.                     else  {multiple column}
  1248.                     begin
  1249.                         If not FirstColumn then   {home}
  1250.                         begin
  1251.                             LoLightFile(HiFn);
  1252.                             HiFn := HiFn - (pred(HiFn) mod ColumnsWide);
  1253.                             HiLightFile(HiFn);
  1254.                         end;
  1255.                     end;
  1256.              #207 : If ColumnsWide = 1  then   {end}
  1257.                     begin
  1258.                         If TotalFiles <= BotFn then
  1259.                         begin
  1260.                              LoLightFile(HiFn);
  1261.                              HiFn := TotalFiles;
  1262.                              HiLightFile(HiFn);
  1263.                         end
  1264.                         else
  1265.                            Scroll_Bottom;
  1266.                     end
  1267.                     else
  1268.                     begin
  1269.                         If not LastColumn then
  1270.                         begin
  1271.                             LoLightFile(HiFn);
  1272.                             HiFn := HiFn
  1273.                                   + Columnswide
  1274.                                   - HiFn mod ColumnsWide;
  1275.                             If HiFn > BotFn then
  1276.                                HiFn := BotFn;
  1277.                             HiLightFile(HiFn);
  1278.                         end;
  1279.                     end;
  1280.              #245 : If HiFn < TotalFiles then      {Ctrl End}
  1281.                     begin
  1282.                         If BotFn = TotalFiles then
  1283.                         begin
  1284.                              LoLightFile(HiFn);
  1285.                              HiFn := TotalFiles;
  1286.                              HiLightFile(HiFn);
  1287.                         end
  1288.                         else
  1289.                         begin
  1290.                            BotFn := TotalFiles;
  1291.                            RecalcTopFn;
  1292.                            HiFn := TotalFiles;
  1293.                            DisplayFiles;
  1294.                         end;
  1295.                     end;
  1296.              #201 : If HiFn > 1 then               {PgUp}
  1297.                     begin
  1298.                         If TopFn > 1 then
  1299.                         begin
  1300.                             TopFn := TopFn - R*ColumnsWide;
  1301.                             If TopFn < 1 then
  1302.                                TopFn := 1;
  1303.                         end;
  1304.                         RecalcBotFn;
  1305.                         HiFN := HiFn - R*ColumnsWide;
  1306.                         If HiFn < 1 then
  1307.                            HiFn := 1;
  1308.                         DisplayFiles;
  1309.                     end;
  1310.              #209 : If Hifn < TotalFiles then      {PgDn}
  1311.                     begin
  1312.                         If BotFn < TotalFiles then
  1313.                         begin
  1314.                             TopFn := TopFN + R*ColumnsWide;
  1315.                             BotFn := BotFn + R*ColumnsWide;
  1316.                             HiFn := HiFn + R*ColumnsWide;
  1317.                             If BotFn > TotalFiles then
  1318.                             begin
  1319.                                 BotFn := TotalFiles;
  1320.                                 RecalcTopFn;
  1321.                                 If  (HiFn < TopFn) then
  1322.                                     Repeat
  1323.                                         HiFn := HiFn + ColumnsWide;
  1324.                                     Until HiFN >= TopFN
  1325.                                 else
  1326.                                     If (HiFn > BotFn)  then
  1327.                                         HiFn := BotFn;
  1328.                             end;
  1329.                             DisplayFiles;
  1330.                         end
  1331.                         else     {Botfn is last file}
  1332.                         begin
  1333.                             LoLightFile(HiFn);
  1334.                             If BottomLine then
  1335.                                 HiFn := BotFn
  1336.                             else
  1337.                                 HiFn := HiFn + R*ColumnsWide;
  1338.                             If HiFn > BotFn then
  1339.                                HiFn := BotFn;
  1340.                             HiLightFile(HiFn);
  1341.                         end;
  1342.                     end;
  1343.              #247 : If HiFn > 1 then      {Ctrl Home}
  1344.                     begin
  1345.                         If TopFn = 1 then
  1346.                         begin
  1347.                              LoLightFile(HiFn);
  1348.                              HiFn := 1;
  1349.                              HiLightFile(HiFn);
  1350.                         end
  1351.                         else
  1352.                            Scroll_Top;
  1353.                     end;
  1354.        DTogglekey : If DTTT.AllowToggle then
  1355.                     begin
  1356.                         ShowingDetails := not ShowingDetails;
  1357.                         If Not ShowingDetails then
  1358.                            ColumnsWide := DTTT.ColsWide
  1359.                         else
  1360.                            Columnswide := 1;
  1361.                         MoveToScreen(Scrn^,mem[BaseofScreen:0],80*DisplayLines);
  1362.                         Calculate_Box_Dimensions;
  1363.                         If Zoomed then
  1364.                         begin
  1365.                             Y3 := DTTT.Zoomline;
  1366.                             R := pred(Y3 - Y2);
  1367.                         end;
  1368.                         TopFn := 0;
  1369.                         Repeat
  1370.                             If TopFN = 0 then
  1371.                                TopFn := 1
  1372.                             else
  1373.                                TopFn := TopFN + R*ColumnsWide;
  1374.                             BotFn := pred( TopFn + ColumnsWide*R);
  1375.                             If BotFn > TotalFiles then
  1376.                             begin
  1377.                                BotFn := TotalFiles;
  1378.                                If BotFn - pred(R*ColumnsWide) > 0 then
  1379.                                   TopFn := BotFN - pred(R*ColumnsWide);
  1380.                             end;
  1381.                         until ((HiFn >= TopFn) and (HiFn <= BotFn));
  1382.                         Display_Box;
  1383.                         FillInfo;
  1384.                         DisplayFiles;
  1385.                     end;
  1386. {$IFDEF DIRFULL}
  1387.          DZoomKey : If DTTT.AllowZoom then
  1388.                     begin
  1389.                         If Zoomed then
  1390.                         begin
  1391.                            MoveToScreen(Scrn^,mem[BaseofScreen:0],80*DisplayLines);
  1392.                             Zoomed := false;
  1393.                             Y3 := Y3_Unzoomed;
  1394.                             R := pred(Y3 - Y2);
  1395.                             RecalcBotFn;
  1396.                             If HiFn > BotFn then
  1397.                                HiFn := BotFn;
  1398.                             Display_Box;
  1399.                             FillInfo;
  1400.                             DisplayFiles;
  1401.                         end
  1402.                         else
  1403.                         begin
  1404.                             If (DTTT.ZoomLine > Y3) and (DTTT.ZoomLine <= DisplayLines) then
  1405.                             begin
  1406.                                 MoveToScreen(Scrn^,mem[BaseofScreen:0],80*DisplayLines);
  1407.                                 Zoomed := true;
  1408.                                 Y3 := DTTT.ZoomLine;
  1409.                                 R := pred(Y3 - Y2);
  1410.                                 RecalcBotFn;
  1411.                                 Display_Box;
  1412.                                 FillInfo;
  1413.                                 DisplayFiles;
  1414.                             end;
  1415.                         end;
  1416.                     end;
  1417.     DSortOrderKey : If DTTT.AllowSort then
  1418.                     begin
  1419.                         SortAsc := not SortAsc;
  1420.                         TopFn := 1;
  1421.                         HiFn := 1;
  1422.                         RecalcBotFn;
  1423.                         DisplayFiles;
  1424.                     end;
  1425.     DSortNameKey  : If DTTT.AllowSort and (SortOrder <> DSortName) then
  1426.                     begin
  1427.                         SortOrder := DSortName;
  1428.                         ReSort;
  1429.                     end;
  1430.     DSortExtKey   : If DTTT.AllowSort and (SortOrder <> DSortExt) then
  1431.                     begin
  1432.                         SortOrder := DSortExt;
  1433.                         ReSort;
  1434.                     end;
  1435.     DSortSizeKey  : If DTTT.AllowSort and (SortOrder <> DSortSize) then
  1436.                     begin
  1437.                         SortOrder := DSortSize;
  1438.                         ReSort;
  1439.                     end;
  1440.     DSortTimeKey  : If DTTT.AllowSort and (SortOrder <> DSortTime) then
  1441.                     begin
  1442.                         SortOrder := DSortTime;
  1443.                         ReSort;
  1444.                     end;
  1445.     DSortDOSKey   : If DTTT.AllowSort and (SortOrder <> DSortDOS) then
  1446.                     begin
  1447.                         SortOrder := DSortDOS;
  1448.                         ReSort;
  1449.                     end;
  1450.     DHelpKey      : If DTTT.AllowHelp then
  1451.                        ShowHelpScreen;
  1452.     DJumpParentKey: If DTTT.AllowCD and (length(PathName) > 3) then  {Enter}
  1453.                     begin
  1454.                         PathName := PathParent(PathName);
  1455.                         Release(DirTop);
  1456.                         DisplayNewDirectory;
  1457.                     end;
  1458.     DChangeDirKey : If DTTT.AllowCD then
  1459.                        PromptForDirectory;
  1460.     #33..#126     :  If DTTT.AllowInput then
  1461.                      begin               {user entered an alpha numeric}
  1462.                          ChosenFile := PromptForFilename(ChD);
  1463.                          If ChosenFile <> '' then
  1464.                          begin
  1465.                              If (ChosenFile[Length(ChosenFile)] = ':') then
  1466.                                  ChosenFile := ChosenFile +'*.*';
  1467.                              If (pos('*',ChosenFile) > 0)
  1468.                              or (pos('?',ChosenFile) > 0)
  1469.                              or (ChosenFile[Length(ChosenFile)] = '\') then
  1470.                              begin
  1471.                                  DIRFULLFileName := ChosenFile;
  1472.                                  Extract_Path_Mask;
  1473.                                  Release(DirTop);
  1474.                                  DisplayNewDirectory;
  1475.                              end
  1476.                              else
  1477.                              begin
  1478.                                 If (pos('\',ChosenFile) = 0)
  1479.                                 and (pos(':',ChosenFile) = 0) then
  1480.                                     ChosenFile := PathName + ChosenFile;
  1481.                                 Finished := true;
  1482.                              end;
  1483.                          end;
  1484.                      end;
  1485. {$ENDIF}
  1486.              #133,                                                 {Mouse left}
  1487.              #13  : If SubDirectory(FilePointer(HiFn)^.Attr) then  {Enter}
  1488.                     begin
  1489.                         If File_Name(HiFn) = '..' then
  1490.                            PathName := PathParent(PathName)
  1491.                         else
  1492.                            PathName := PathChild(File_Name(HiFn));
  1493.                         If (DTTT.SelectDir = false) then
  1494.                         begin
  1495.                            Release(DirTop);
  1496.                            DisplayNewDirectory;
  1497.                         end
  1498.                         else                      {return the Directory}
  1499.                         begin
  1500.                             Finished := true;
  1501.                             ChosenFile := PathNoSlash(PathName);
  1502.                         end;
  1503.                     end
  1504.                     else
  1505.                     begin
  1506.                         Finished := true;
  1507.                         ChosenFile := PathName+File_Name(HiFn);
  1508.                     end;
  1509.              #132,                          {mouse right}
  1510.              #027 : begin                   {esc}
  1511.                         Finished := true;
  1512.                         Retcode := EscCode;
  1513.                         ChosenFile := '';
  1514.                     end;
  1515.              end;  {case}
  1516.              If TotalFiles = 0 then
  1517.              begin
  1518.        {$IFDEF DIRFULL}
  1519.                    Repeat
  1520.                       Case No_Files_Found of
  1521.                       0 : exit;  {user selected a file}
  1522.                       99: begin  {user escaped}
  1523.                                Retcode := NoFilesCode;
  1524.                                Exit;
  1525.                             end;
  1526.                       end; {case}
  1527.                    until TotalFiles <> 0;
  1528.        {$ELSE}
  1529.                 Retcode := NoFilesCode;
  1530.                 Exit;
  1531.        {$ENDIF}
  1532.              end;
  1533.         Until Finished;
  1534.     end; {sub proc Process_Keys}
  1535.  
  1536.     Procedure SaveInitScreen;
  1537.     var S : word;
  1538.     begin
  1539.         S := 160*DisplayLines;
  1540.         If MaxAvail < S then
  1541.            NoMemory := true
  1542.         else
  1543.         begin
  1544.             Getmem(Scrn,160*DisplayLines);
  1545.             MoveFromScreen(Mem[BaseOfScreen:0],Scrn^,S div 2);
  1546.             FindCursor(CursRec[1],Cursrec[2],Cursrec[3],Cursrec[4]);
  1547.             OffCursor;
  1548.         end;
  1549.     end;
  1550.  
  1551.     Procedure Clear;
  1552.     begin
  1553.         If DTTT.RestoreScreen then
  1554.             MoveToScreen(Scrn^,mem[BaseofScreen:0],80*DisplayLines);
  1555.         PosCursor(Cursrec[1],Cursrec[2]);
  1556.         SizeCursor(Cursrec[3],Cursrec[4]);
  1557.         Release(HeapTop);
  1558.     end;
  1559.  
  1560. begin          {main procedure}
  1561.     Mark(HeapTop);
  1562.     NoMemory := False;
  1563.     Zoomed := False;
  1564.     ShowingDetails := DTTT.ShowDetails;
  1565.     SortAsc := DTTT.Asc = 1;
  1566.     SortOrder := DTTT.InitSort;
  1567.     If Not ShowingDetails then
  1568.        ColumnsWide := DTTT.ColsWide
  1569.     else
  1570.        Columnswide := 1;
  1571.     SaveInitScreen;
  1572.     If NoMemory then
  1573.     begin
  1574.         Retcode := Memcode;
  1575.         exit;
  1576.     end;
  1577.     {$I-}
  1578.     GetDir(0,StartDir);
  1579.     {SI+}
  1580.     If IOResult <> 0 then
  1581.     begin
  1582.         Retcode := UnknownCode;
  1583.         exit;
  1584.     end;
  1585.     Retcode := OKCode;     {assume it will succeed!}
  1586.     Extract_Path_Mask;
  1587.     Calculate_Box_Dimensions;
  1588.     Y3_unzoomed := Y3;   {ugh?}
  1589.     DisplayNewDirectory;
  1590.     If NoMemory then
  1591.     begin
  1592.        Clear;
  1593.        Retcode := Memcode;
  1594.     end
  1595.     else
  1596.        Process_Keys;
  1597.     Clear;
  1598.     Display_Directory := ChosenFile;
  1599. end;
  1600.  
  1601. begin
  1602.     Default_Settings;
  1603.     Horiz_Sensitivity := 3;
  1604. end.
  1605.